﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace WebApiDemo.Services
{
    public class AreaSerivce : IAreaSerivce
    {
        public IList<Area> SelectAreaList(string areaId, int? level, string langType)
        {
            var context = new RegionContext();
            var len = areaId.Length;
            var list = (from d in context.DArea
                        join s in context.SysLang on d.VcAreaName equals s.VcCode
                        where s.ELangType == langType && d.LLevel == level && d.VcAreaId != areaId && d.VcAreaId.Substring(0, len) == areaId
                        select new Area
                        {
                            Code = d.VcAreaId,
                            Key = d.VcAreaName,
                            Value = s.VcName,
                            Level = d.LLevel.Value.ToString()
                        })
                        .ToList();

            return list;
        }

        public IList<Area> GetAllCountry(string langType)
        {
            var context = new RegionContext();
            var list = (from d in context.DArea
                        join s in context.SysLang on d.VcAreaName equals s.VcCode
                        where s.ELangType == langType && d.LLevel == 0
                        select new Area
                        {
                            Code = d.VcAreaId,
                            Key = d.VcAreaName,
                            Value = s.VcName,
                            Level = d.LLevel.Value.ToString()
                        })
                        .ToList();

            return list;
        }
    }
}     
